/**
 * @class   wosh::gui::DialogLoadBundle
 * @brief   
 *          
 *          
 *
 ****************************************************************************
 * @version $Id: DialogLoadBundle.h 2488 2010-05-21 01:48:27Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Gui_DialogLoadBundle_H__
 #define __WOSH_Gui_DialogLoadBundle_H__

 #include <framework/gui/IWidget.h>
 #include <core/List.h>
 #include <core/URI.h>

 #include <core/Request.h>
 #include <core/Response.h>
 #include <core/List.h>
 #include <core/WoshKernel.h>
 #include <core/MethodsCommon.h>

 #include <QtGui>
 #include <QtGui/QDialog>
 #include <QtGui/QListWidgetItem>

 #include "ui_DialogLoadBundle.h"


namespace wosh {
 namespace gui {


class DialogLoadBundle : public QDialog, public IWidget  {

	Q_OBJECT

	public:

		DialogLoadBundle(QWidget *parent = 0) : QDialog(parent), IWidget() {
			this->m_ui = new Ui::DialogLoadBundle();
			this->m_ui->setupUi(this);

			this->setWindowTitle("Load Bundle..");
			this->getWidgetURI().setName("DialogLoadBundle");
			this->getTargetURI().setAny();

			connect(this->m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
			connect(this->m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

			connect(this->m_ui->listWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemClicked(QListWidgetItem*)));

			refreshAll();
		 }
		virtual ~DialogLoadBundle() {
			delete this->m_ui;
		 }


		virtual QWidget* asQWidget()		{ return this; }

	public:

		virtual void busMessage( const Message& message, const Bus* source ) {
			(void)source;
			if ( message.isEmpty() ) return;
		 }


		virtual std::string& getName()			{ return this->itemName; }
		virtual std::string& getAllocator()		{ return this->itemAllocator; }

	public slots:
		virtual void refreshAll() {
/*
			 this->m_ui->listWidget->clear();
			List<BundleAllocator*>& bundleAllocators = WoshKernel::getInstance()->bundles().getBundleAllocator();

			bundleAllocators.mutex().lockForRead();
			if ( bundleAllocators.size_() > 0 ) {
				std::vector<BundleAllocator*>::const_iterator it;
				std::vector<BundleAllocator*>::const_iterator it_end = bundleAllocators.stdEnd();
				for ( it=bundleAllocators.stdBegin(); it!=it_end; it++ ) {
					if ( *it == NULL ) continue;
					std::vector<std::string> obj_list;
					(*it)->getSupportedObjects(obj_list);

					std::vector<string>::const_iterator its;
					for ( its=obj_list.begin(); its!=obj_list.end(); its++ ) {
						QListWidgetItem* item = new QListWidgetItem(this->m_ui->listWidget);
						item->setText( (*its).c_str() );
						item->setData(Qt::ToolTipRole, (*it)->getName().c_str() );
						this->m_ui->listWidget->addItem( item );
					 }
				 }
			 }
			bundleAllocators.mutex().unLock();
*/
		 }

		void itemClicked(QListWidgetItem* item) {
			if ( item == NULL ) return;
			this->itemName = std::string(item->text().toLatin1().data());
			this->itemAllocator = std::string(item->data(Qt::ToolTipRole).toString().toLatin1().data());
		 }

	protected:

		void changeEvent(QEvent *e) {
			QWidget::changeEvent(e);
			switch (e->type()) {
			case QEvent::LanguageChange:
				m_ui->retranslateUi(this);
				break;
			default:
				break;
			}
		 }

		std::string itemName;
		std::string itemAllocator;

	private:
		Ui::DialogLoadBundle *m_ui;

}; // class def

 }; // namespace gui
}; // namespace wosh


#endif // __WOSH_Gui_DialogLoadBundle_H__
